<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="com.sun.org.apache.xpath.internal.operations.Bool" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%--项目绝对路径--%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<%

    String url = "jdbc:mysql://localhost:3306/carxianyu";
    String user = "root";
    String pwd = "root";



    String sql = "select * from car ";

    //jdbc 连接数据库
    Class.forName("com.mysql.jdbc.Driver");//加载驱动
    Connection conn = DriverManager.getConnection("jdbc:mysql://43.142.239.28:13307/carxianyu?useUnicode=true&characterEncoding=UTF-8&serverTimeZone=UTC","root","root");
    PreparedStatement a = conn.prepareStatement(sql);
    ResultSet rs = a.executeQuery();
    System.out.println("执行了sql =====》"+sql);


%>


<head>
    <title>车辆列表</title>
    <!-- 引入css样式和js文件-->
    <meta charset="UTF-8">
    <base href="${ctx}/"/>
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${ctx}/static/layui/layui.js"></script>
</head>
<body>
<div class="layui-fluid">

    <div>

    </div>

    <table class="layui-table">
        <tbody>
        <tr class="layui-bg-blue">
            <th>车名</th>
            <th>车牌</th>
            <th>车价格</th>
            <th>车龄</th>
            <th>变速箱</th>
            <th>地址</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        <% while(rs.next()){

            //为列表参数初始化

            String number  = rs.getString("number");
            Integer id = rs.getInt("id");
            String name = rs.getString("name");
            String images = rs.getString("images");
            String price = rs.getString("price");
            String introduction = rs.getString("introduction");
            String address = rs.getString("address");
            Integer age =Integer.valueOf( rs.getString("age"));
            String createtime = rs.getString("createtime");
            String identity = rs.getString("identity");
            String phone = rs.getString("phone");
            Integer collection =Integer.valueOf( rs.getString("collection"));
            Integer gearboxId =Integer.valueOf( rs.getString("gearbox"));
            Integer statusid = Integer.valueOf( rs.getString("status"));

            String status = null;

            Boolean isShenhe = false;
            if(statusid == 11){
                isShenhe = true;
                status = "待审核";
            }else if(statusid == 22){
                isShenhe = false;
                status = "审核通过";
            }else {
                isShenhe = true;
                status = "审核拒绝";
            }


            String gearbox = null;
            if(gearboxId == 11){
               gearbox = "手动档";
            }else {
                gearbox= "自动档";
            }



            String updateUri ="/view/back/car/carUpdate.jsp?id="+id;
            String deleteUri = "/view/back/car/doCarExcute.jsp?state=3&id="+id;
            String detailUri ="/view/back/car/carDetail.jsp?id="+id;
        %>
        <tr>
            <td><%=name%></td>
            <td><%=number%></td>
            <td><%=price%></td>
            <td><%=age%></td>
            <td><%=gearbox%></td>

            <td><%=address%></td>
            <td><%=status%></td>
            <td style="width: 180px;">
                <a href="${ctx}<%=updateUri%>" class="layui-btn layui-btn layui-btn-sm">修改</a>
                <a href="${ctx}<%=deleteUri%>" class="layui-btn layui-btn-danger layui-btn-sm">删除</a>

                <c:if test="<%=!isShenhe%>">
                    <button path="${ctx}<%=detailUri%>"
                            class="layui-btn layui-btn-normal layui-btn-sm showDetail">详情
                    </button>
                </c:if>
                <c:if test="<%=isShenhe%>">
                    <button path="${ctx}<%=detailUri%>"
                            class="layui-btn layui-btn-danger layui-btn-sm showDetail">审核
                    </button>
                </c:if>



            </td>




        </tr>

        <%}%>
        </tbody>
    </table>


</div>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    //定义layui的变量
    var $;
    var layer;
    var element;
    var form;
    layui.use(['element', 'layer', 'jquery', 'form'], function () {
        element = layui.element;
        layer = layui.layer;
        $ = layui.jquery;
        form = layui.form;
        //绑定详情点击事件
        $(".showDetail").click(function () {
            var path = $(this).attr("path");
            layer.open({
                offset: '100px', //设置弹出窗口的位置 上边距100px
                type: 2,  //弹出类型
                skin: 'layui-layer-molv', //样式类名
                title: '详情查看',
                anim: 2,    //弹出窗口使用的动画
                area: ['800px', '620px'],  //设置弹出窗口的大小 宽度,高度
                shadeClose: true, //开启遮罩关闭
                content: path  //加载内容路径
            });
        })
    });
</script>

</body>
</html>
